﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using gfLibrary;
using DBUtility;
using Model;
using BLL;

namespace GreatGF
{
    public partial class DEV_STANDARD_ASM_Insert_Update : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {

                string strMode = Request["m"];

                if((strMode == "u")||(strMode == "b")||(strMode == "r"))
                {
                    string strId = Request["UniqueKey"];

                    DEV_STANDARD_ASM_BLL m_DEV_STANDARD_ASM_BLL = new DEV_STANDARD_ASM_BLL();

                    if(m_DEV_STANDARD_ASM_BLL.Exists(Convert.ToInt32(strId)) == true)
                    {
                        DEV_STANDARD_ASM m_DEV_STANDARD_ASM = new DEV_STANDARD_ASM();
                        m_DEV_STANDARD_ASM = m_DEV_STANDARD_ASM_BLL.GetModel(Convert.ToInt32(strId));

                        txtID.Text = m_DEV_STANDARD_ASM.ID.ToString();
                        txtSEARCH_CONDITION.Text = m_DEV_STANDARD_ASM.SEARCH_CONDITION;
                        txtZXMC.Text = m_DEV_STANDARD_ASM.ZXMC;
                        txtHC5025XZ.Text = m_DEV_STANDARD_ASM.HC5025XZ;
                        txtCO5025XZ.Text = m_DEV_STANDARD_ASM.CO5025XZ;
                        txtNO5025XZ.Text = m_DEV_STANDARD_ASM.NO5025XZ;
                        txtHC2540XZ.Text = m_DEV_STANDARD_ASM.HC2540XZ;
                        txtCO2540XZ.Text = m_DEV_STANDARD_ASM.CO2540XZ;
                        txtNO2540XZ.Text = m_DEV_STANDARD_ASM.NO2540XZ;
                        txtDSHCXZ.Text = m_DEV_STANDARD_ASM.DSHCXZ;
                        txtDSCOXZ.Text = m_DEV_STANDARD_ASM.DSCOXZ;
                        txtIS_SHOW.Text = m_DEV_STANDARD_ASM.IS_SHOW.ToString();
                        txtAREA_NAME.Text = m_DEV_STANDARD_ASM.AREA_NAME;
                        txtUTYPE.Text = m_DEV_STANDARD_ASM.UTYPE.ToString();
                    }
                    else
                    {
                        gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                        gfAjaxJs.SetGoToUrl(this.UpdatePanel1, "DEV_STANDARD_ASM_List.aspx");
                    }

                    if((strMode == "b")||(strMode == "r"))
                    {
                        txtID.ReadOnly = true;
                        txtID.CssClass = "csstextboxreadonly";
                        txtSEARCH_CONDITION.ReadOnly = true;
                        txtSEARCH_CONDITION.CssClass = "csstextboxreadonly";
                        txtZXMC.ReadOnly = true;
                        txtZXMC.CssClass = "csstextboxreadonly";
                        txtHC5025XZ.ReadOnly = true;
                        txtHC5025XZ.CssClass = "csstextboxreadonly";
                        txtCO5025XZ.ReadOnly = true;
                        txtCO5025XZ.CssClass = "csstextboxreadonly";
                        txtNO5025XZ.ReadOnly = true;
                        txtNO5025XZ.CssClass = "csstextboxreadonly";
                        txtHC2540XZ.ReadOnly = true;
                        txtHC2540XZ.CssClass = "csstextboxreadonly";
                        txtCO2540XZ.ReadOnly = true;
                        txtCO2540XZ.CssClass = "csstextboxreadonly";
                        txtNO2540XZ.ReadOnly = true;
                        txtNO2540XZ.CssClass = "csstextboxreadonly";
                        txtDSHCXZ.ReadOnly = true;
                        txtDSHCXZ.CssClass = "csstextboxreadonly";
                        txtDSCOXZ.ReadOnly = true;
                        txtDSCOXZ.CssClass = "csstextboxreadonly";
                        txtIS_SHOW.ReadOnly = true;
                        txtIS_SHOW.CssClass = "csstextboxreadonly";
                        txtAREA_NAME.ReadOnly = true;
                        txtAREA_NAME.CssClass = "csstextboxreadonly";
                        txtUTYPE.ReadOnly = true;
                        txtUTYPE.CssClass = "csstextboxreadonly";
                        btnSave.Visible = false;
                    }

                    if(strMode == "r")
                    {
                        btnBack.Visible = false;
                    }
                }
                if (strMode == "i")
                {
                    lblOperateType.Text = "添加";
                }
                if (strMode == "b" || strMode == "r")
                {
                    lblOperateType.Text = "查看";
                }
                if (strMode == "u")
                {
                    lblOperateType.Text = "修改";
                }
            }

            btnBack.Attributes["onclick"] = "javascript:window.location.href='DEV_STANDARD_ASM_List.aspx';return false;";
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strID = txtID.Text.Trim();
            string strSEARCH_CONDITION = txtSEARCH_CONDITION.Text.Trim();
            string strZXMC = txtZXMC.Text.Trim();
            string strHC5025XZ = txtHC5025XZ.Text.Trim();
            string strCO5025XZ = txtCO5025XZ.Text.Trim();
            string strNO5025XZ = txtNO5025XZ.Text.Trim();
            string strHC2540XZ = txtHC2540XZ.Text.Trim();
            string strCO2540XZ = txtCO2540XZ.Text.Trim();
            string strNO2540XZ = txtNO2540XZ.Text.Trim();
            string strDSHCXZ = txtDSHCXZ.Text.Trim();
            string strDSCOXZ = txtDSCOXZ.Text.Trim();
            string strIS_SHOW = txtIS_SHOW.Text.Trim();
            string strAREA_NAME = txtAREA_NAME.Text.Trim();
            string strUTYPE = txtUTYPE.Text.Trim();

            if (gfValidate.Is_Integer(strIS_SHOW) == false)
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "[IS_SHOW]不是有效的数字格式。");
                return;
            }
            if (gfValidate.Is_Integer(strUTYPE) == false)
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "[UTYPE]不是有效的数字格式。");
                return;
            }

            DEV_STANDARD_ASM m_DEV_STANDARD_ASM = new DEV_STANDARD_ASM();
            DEV_STANDARD_ASM_BLL m_DEV_STANDARD_ASM_BLL = new DEV_STANDARD_ASM_BLL();

            m_DEV_STANDARD_ASM.SEARCH_CONDITION = strSEARCH_CONDITION;
            m_DEV_STANDARD_ASM.ZXMC = strZXMC;
            m_DEV_STANDARD_ASM.HC5025XZ = strHC5025XZ;
            m_DEV_STANDARD_ASM.CO5025XZ = strCO5025XZ;
            m_DEV_STANDARD_ASM.NO5025XZ = strNO5025XZ;
            m_DEV_STANDARD_ASM.HC2540XZ = strHC2540XZ;
            m_DEV_STANDARD_ASM.CO2540XZ = strCO2540XZ;
            m_DEV_STANDARD_ASM.NO2540XZ = strNO2540XZ;
            m_DEV_STANDARD_ASM.DSHCXZ = strDSHCXZ;
            m_DEV_STANDARD_ASM.DSCOXZ = strDSCOXZ;
            m_DEV_STANDARD_ASM.IS_SHOW = Convert.ToInt32(strIS_SHOW);
            m_DEV_STANDARD_ASM.AREA_NAME = strAREA_NAME;
            m_DEV_STANDARD_ASM.UTYPE = Convert.ToInt32(strUTYPE);

            if (string.IsNullOrEmpty(strID) == true)
            {
                strID = "-1";
            }

            if (m_DEV_STANDARD_ASM_BLL.Exists(Convert.ToInt32(strID)) == false)
            {
                //m_DEV_STANDARD_ASM.ID = m_DEV_STANDARD_ASM_BLL.GetMax_ID();

                if (m_DEV_STANDARD_ASM_BLL.Insert(m_DEV_STANDARD_ASM) == true)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "新增成功！");
                    txtID.Text = m_DEV_STANDARD_ASM.ID.ToString();
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "新增失败！");
                }
            }
            else
            {
                if (m_DEV_STANDARD_ASM_BLL.Update(m_DEV_STANDARD_ASM, Convert.ToInt32(strID)) == true)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "更新成功！");
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "更新失败！");
                }
            }
        }
    }
}
